package com.ljz.controller.app;

import com.ljz.common.core.controller.MyBaseController;
import com.ljz.common.dao.bean.PageResult;
import com.ljz.common.utils.ReturnResult;
import com.ljz.entity.Order;
import com.ljz.query.OrderQuery;
import com.ljz.service.OrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/app")
@Api(tags = "订单信息管理")
public class OrderController extends MyBaseController {
    @Autowired
    private OrderService orderService;

    @ApiOperation("添加订单")
    @PostMapping("/saveOrder")
    public ReturnResult insertOrder(@RequestBody Order order) {
        //生成订单
        int re=orderService.saveEntity(order);
        return success("生成订单成功");
    }

    @ApiOperation("删除订单")
    @PutMapping("/deleteOrder")
    public ReturnResult deleteOrder(Integer id) {
        int re=orderService.deleteEntity(id);
        return deleteResult(re);
    }

    @ApiOperation("修改订单")
    @PutMapping("/updateOrder")
    public ReturnResult updateOrder(@RequestBody Order order) {
        int re=orderService.updateEntity(order);
        return saveResult(re);
    }

    @ApiOperation("根据用户id查询订单")
    @PostMapping("/getOrderByUserId")
    public ReturnResult<PageResult> getOrderByUserId(@RequestBody OrderQuery orderQuery) {
        PageResult pageResult = orderService.queryByPage(orderQuery);
        return success("根据用户id查询的订单",pageResult);
    }

    @ApiOperation("根据订单编码查询的订单")
    @PostMapping("/getOrderByCode")
    public ReturnResult getOrderByCode(String code) {
        return success("根据订单编码查询的订单",orderService.getOrderByCode(code));
    }

    @ApiOperation("根据订单编码删除订单")
    @PutMapping("/deleteOrderById")
    public ReturnResult deleteOrderById(String orderCode) {
        int re=orderService.deleteEntity(orderCode);
        return deleteResult(re);
    }

    @ApiOperation("批量添加订单")
    @PostMapping("/savaBatch")
    public ReturnResult savaBatch(@RequestBody List<Order> orders) {
        int re=orderService.saveBatch(orders);
        return saveResult(re);
    }

    @ApiOperation("所有订单总金额")
    @PostMapping("/getOrdersActualAmount")
    public ReturnResult getOrdersActualAmount(List<String> orderCodes) {
        return success("所有订单总金额",orderService.getOrdersActualAmount(orderCodes));
    }

}
